package com.taorenqi.business.fragment.mine.more;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.taorenqi.business.R;
import com.taorenqi.business.activity.LoginActivity;
import com.taorenqi.business.fragment.base.BaseBackFragment;
import com.taorenqi.business.widget.statusview.StatusView;
import com.taorenqi.data.cache.ACache;
import com.taorenqi.data.cache.EnumKey;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 更多
 * A simple {@link Fragment} subclass.
 */
public class MoreFragment extends BaseBackFragment {


    @Bind(R.id.status_view)
    StatusView statusView;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.more_change_phone)
    TextView moreChangePhone;
    @Bind(R.id.more_change_login_pwd)
    TextView moreChangeLoginPwd;
    @Bind(R.id.more_about_us)
    TextView moreAboutUs;
    @Bind(R.id.more_quit)
    TextView moreQuit;

    public static MoreFragment newInstance() {
        // Required empty public constructor
        MoreFragment fragment = new MoreFragment();
        Bundle bundle = new Bundle();
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_more2, container, false);
        ButterKnife.bind(this, view);
        toolbar.setTitle("更多");
        initToolbarNav(toolbar);
        return attachToSwipeBack(view);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.more_change_phone, R.id.more_change_login_pwd, R.id.more_about_us, R.id.more_quit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.more_change_phone:
                start(ChangePhoneFragment.newInstance());
                break;
            case R.id.more_change_login_pwd:
                start(ModifyLoginPwdFragment.newInstance());
                break;
            case R.id.more_about_us:
                start(AboutUsFragment.newInstance());
                break;
            case R.id.more_quit:
                ACache.get(_mActivity).put(EnumKey.User.USER_TOKEN, "");

                Intent intent = new Intent();
                intent.setClass(_mActivity, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                break;
        }
    }
}
